/*
 * This file is part of Avenge <https://avenge.cn/>,
 * Copyright (C) 2006-present eyeo GmbH
 *
 * Avenge is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * Avenge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Avenge.  If not, see <http://www.gnu.org/licenses/>.
 */

"use strict";

{
  window.ext = {};

  let EventTarget = ext._EventTarget = function()
  {
    this._listeners = new Set();
  };
  EventTarget.prototype = {
    addListener(listener)
    {
      this._listeners.add(listener);
    },
    removeListener(listener)
    {
      this._listeners.delete(listener);
    },
    _dispatch(...args)
    {
      let results = [];

      for (let listener of this._listeners)
        results.push(listener(...args));

      return results;
    }
  };


  /* Message passing */

  ext.onMessage = new ext._EventTarget();
}
